﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using suirui.ZhuMu.Model;

namespace suirui.ZhuMu.Common.Utils
{
    public static class APIResultMessageExtend
    {
        public static void ResetInnerError(this APIResult result)
        {
            result.Code = (int)PublicErrorCode.InnerError;
            result.Message = MessageCollection.InnerError;
        }

        public static void ResetForbiddenError(this APIResult result)
        {
            result.Code = (int)PublicErrorCode.Forbidden;
            result.Message = MessageCollection.ForbiddenError;
        }
        public static void ResetCheckCodeError(this APIResult result)
        {
            result.Code = (int)PublicErrorCode.CheckCodeError;
            result.Message = MessageCollection.ForbiddenError;
        }
        public static void ResetTooManyFailedAttemptsError(this APIResult result)
        {
            result.Code = (int)PublicErrorCode.TooManyFailedAttempts;
            result.Message = MessageCollection.TooManyFailedAttempts;
        }
        public static void ResetViewerNoPerssionError(this APIResult result)
        {
            result.Code = (int)PublicErrorCode.ViewerNoPermission;
            result.Message = MessageCollection.ViewerNoPermission;
        }

        public static void ResetNoDataError(this APIResult result)
        {
            result.Code = (int)PublicErrorCode.DataNotExist;
            result.Message = MessageCollection.DataNotExist;
        }
        public static void ResetAuthTypeChangedError(this APIResult result)
        {
            result.Code = (int)PublicErrorCode.AuthTypeChanged;
            result.Message = MessageCollection.AuthTypeChanged;
        }
        public static void ResetIllegallyNameError(this APIResult result)
        {
            result.Code = (int)PublicErrorCode.IllegallyName;
            result.Message = MessageCollection.IllegallyName;
        }

        public static void ResetPictureCodeError(this APIResult result)
        {
            result.Code = (int)PublicErrorCode.PictureCodeError;
            result.Message = MessageCollection.PictureCodeError;
        }
        public static void ResetTooManyGetMeesageCodeError(this APIResult result)
        {
            result.Code = (int)PublicErrorCode.TooManyGetMeesageCode;
            result.Message = MessageCollection.TooManyGetMeesageCode;
        }

        public static void ResetError(this APIResult result, int code)
        {
            if (code != (int)PublicErrorCode.Success)
            {
                if (code == (int)PublicErrorCode.Forbidden)
                {
                    result.ResetForbiddenError();
                }
                else if (code == (int)PublicErrorCode.CheckCodeError)
                {
                    result.ResetCheckCodeError();
                }
                else if (code == (int)PublicErrorCode.TooManyFailedAttempts)
                {
                    result.ResetTooManyFailedAttemptsError();
                }
                else if (code == (int)PublicErrorCode.ViewerNoPermission)
                {
                    result.ResetViewerNoPerssionError();
                }
                else if (code == (int)PublicErrorCode.DataNotExist)
                {
                    result.ResetNoDataError();
                }
                else if (code == (int)PublicErrorCode.AuthTypeChanged)
                {
                    result.ResetAuthTypeChangedError();
                }
                else if (code == (int)PublicErrorCode.IllegallyName)
                {
                    result.ResetIllegallyNameError();
                }
                else if (code == (int)PublicErrorCode.PictureCodeError)
                {
                    result.ResetPictureCodeError();
                }
                else if (code == (int)PublicErrorCode.TooManyGetMeesageCode)
                {
                    result.ResetTooManyGetMeesageCodeError();
                }
                else
                {
                    result.ResetInnerError();
                }
            }
        }
    }
}
